/*******************************************************************************
02_05: Make Table 5: Effect of an increase in GGI from India's to Canada's value
	on the gender gap in non-market work for immigrants

Replication code for "Culture and gender allocation of tasks: source country 
	characteristics and the division of non-market work among US immigrants" in
	Review of Economics of the Household

Authors: Francine Blau, Lawrence Kahn, Matthew Comey, Amanda Eng, Pamela 
	Meyerhofer, and Alexander Willen
	
Date: 10/16/2020

Description: This code generates Table 5

*******************************************************************************/


/*******************************************************************************

I. Set labels and controls

*******************************************************************************/

***A. Set table labels
putexcel set "$tables/Table_5", replace

putexcel A1="Table 5: Effect of an increase in GGI from India's to Canada's value on the gender gap in non-market work for immigrants", bold

putexcel A2="I. Mean Values", bold
putexcel A3="Panel A. All Immigrants", italic
putexcel F3="Panel B. Immigrants with at Least One Child Under 18", italic
putexcel B4="Women"
putexcel C4="Men"
putexcel D4="W-M"
putexcel G4="Women"
putexcel H4="Men"
putexcel I4="W-M"

putexcel A8="II. Effect of a 0.12 change in GGI (India to Canada)", bold
putexcel A9="Panel A. All Immigrants", italic
putexcel F9="Panel B. Immigrants with at Least One Child Under 18", italic
putexcel B10="Women"
putexcel C10="Men"
putexcel D10="W-M"
putexcel E10="(W-M)/Mean Gap"
putexcel G10="Women"
putexcel H10="Men"
putexcel I10="W-M"
putexcel J10="(W-M)/Mean Gap"

putexcel A5="Total"
putexcel A6="Housework"
putexcel A7="Childcare"
putexcel A11="Total"
putexcel A13="Housework"
putexcel A15="Childcare"

putexcel F5="Total"
putexcel F6="Housework"
putexcel F7="Childcare"
putexcel F11="Total"
putexcel F13="Housework"
putexcel F15="Childcare"


***B. Set control variables
local controls age age2 RACE2 RACE3 RACE4 RACE5 yrsusa1 yrsusa2 cohort70_79 cohort80_89 cohort90_99 cohort00_09 cohort10_17

local fe i.day i.month i.year i.state

local ecp_controls hsdi scol cold young_children middle_children old_children part_age part_age2 part_hsdi part_scol part_cold part_RACE2 part_RACE3 part_RACE4 part_RACE5 part_immig part_secondgen part_yrsusa1 part_yrsusa2 part_cohort70_79 part_cohort80_89 part_cohort90_99 part_cohort00_09 part_cohort10_17

local wife_work wifehours wifehours_vary


/*******************************************************************************

III. Fill in Table

*******************************************************************************/

***Panel I

local row = 5

foreach var in $nmw $hwork $ccare  {
	
	**All immigrants
	*Women
	qui reg `var' GGI GDP_000 fertility `controls' `ecp_controls' `fe' if female==1 & immig==1 [aw=newwt], robust cluster(bpl) 
	qui sum `var' [aw=newwt] if e(sample), mean
	local m_f = r(mean)
	putexcel B`row' = `m_f', nformat("#.00")
	
	* Men
	qui reg `var' GGI GDP_000 fertility `controls' `ecp_controls' `fe' if female==0 & immig==1 [aw=newwt], robust cluster(bpl) 
	qui sum `var' [aw=newwt] if e(sample), mean
	local m_m = r(mean)
	putexcel C`row' = `m_m', nformat("#.00")
	
	*Difference
	local diff = `m_f' - `m_m'
	putexcel D`row' = `diff', nformat("#.00")
	
	
	**Immigrants with Children
	*Women
	qui reg `var' GGI GDP_000 fertility `controls' `ecp_controls' `fe' if female==1 & immig==1 & youngc<18 & hh_numownkids!=0 [aw=newwt], robust cluster(bpl)
	qui sum `var' [aw=newwt] if e(sample), mean
	local m_f = r(mean)
	putexcel G`row' = `m_f', nformat("#.00")
	
	* Men
	qui reg `var' GGI GDP_000 fertility `controls' `ecp_controls' `fe' if female==0 & immig==1 & youngc<18 & hh_numownkids!=0 [aw=newwt], robust cluster(bpl)
	qui sum `var' [aw=newwt] if e(sample), mean
	local m_m = r(mean)
	putexcel H`row' = `m_m', nformat("#.00")
	
	*Difference
	local diff = `m_f' - `m_m'
	putexcel I`row' = `diff', nformat("#.00")
	
	
	local row = `row' + 1
	
	}
	
	
***Panel II

local row1 = 11
local row2 = 12

foreach var in $nmw $hwork $ccare  {
	
	**All immigrants
	*Women
	qui reg `var' GGI GDP_000 fertility `controls' `ecp_controls' `fe' if female==1 & immig==1 [aw=newwt], robust cluster(bpl) 
	local f_est = _b[GGI] * .12
	local f_ste = _se[GGI] * .12
	local f_dof = e(df_r)
	
	qui sum `var' [aw=newwt] if e(sample), mean
	local m_f = r(mean)
	
	getstars `f_est' `f_ste' `f_dof'
	putexcel B`row1' = (r(eststar))
	putexcel B`row2' = `f_ste', nformat("(0.000)")
	
	* Men
	qui reg `var' GGI GDP_000 fertility `controls' `ecp_controls' `fe' if female==0 & immig==1 [aw=newwt], robust cluster(bpl) 
	local m_est = _b[GGI] * .12
	local m_ste = _se[GGI] * .12
	local m_dof = e(df_r)
	
	qui sum `var' [aw=newwt] if e(sample), mean
	local m_m = r(mean)
	
	getstars `m_est' `m_ste' `m_dof'
	putexcel C`row1' = (r(eststar))
	putexcel C`row2' = `m_ste', nformat("(0.000)")
	
	*Difference
	local d_est = `f_est' - `m_est'
	local d_ste = sqrt(`f_ste'^2 + `m_ste'^2)
	
		*Welch-Satterthwaite corrected DoF
		local d_dof = ( ( (`f_ste')^2 + (`m_ste')^2 )^2 )  /  ( ( (`f_ste')^4 / (`f_dof') ) + ( (`m_ste')^4 / (`m_dof')  ) )
		
	getstars `d_est' `d_ste' `d_dof'
	putexcel D`row1' = (r(eststar))
	putexcel D`row2' = `d_ste', nformat("(0.000)")
	
	*Scaled difference
	local m_diff = `m_f' - `m_m'
	local scd_est = `d_est' / `m_diff'
	local scd_ste = `d_ste' / `m_diff'
		
	getstars `scd_est' `scd_ste' `d_dof'
	putexcel E`row1' = (r(eststar))
	putexcel E`row2' = `scd_ste', nformat("(0.000)")
	
	
	
	**Immigrants with Children
	*Women
	qui reg `var' GGI GDP_000 fertility `controls' `ecp_controls' `fe' if female==1 & immig==1 & youngc<18 & hh_numownkids!=0 [aw=newwt], robust cluster(bpl)
	local f_est = _b[GGI] * .12
	local f_ste = _se[GGI] * .12
	local f_dof = e(df_r)
	
	qui sum `var' [aw=newwt] if e(sample), mean
	local m_f = r(mean)
	
	getstars `f_est' `f_ste' `f_dof'
	putexcel G`row1' = (r(eststar))
	putexcel G`row2' = `f_ste', nformat("(0.000)")
	
	* Men
	qui reg `var' GGI GDP_000 fertility `controls' `ecp_controls' `fe' if female==0 & immig==1 & youngc<18 & hh_numownkids!=0 [aw=newwt], robust cluster(bpl)
	local m_est = _b[GGI] * .12
	local m_ste = _se[GGI] * .12
	local m_dof = e(df_r)
	
	qui sum `var' [aw=newwt] if e(sample), mean
	local m_m = r(mean)
	
	getstars `m_est' `m_ste' `m_dof'
	putexcel H`row1' = (r(eststar))
	putexcel H`row2' = `m_ste', nformat("(0.000)")
	
	*Difference
	local d_est = `f_est' - `m_est'
	local d_ste = sqrt(`f_ste'^2 + `m_ste'^2)
	
		*Welch-Satterthwaite corrected DoF
		local d_dof = ( ( (`f_ste')^2 + (`m_ste')^2 )^2 )  /  ( ( (`f_ste')^4 / (`f_dof') ) + ( (`m_ste')^4 / (`m_dof')  ) )
		
	getstars `d_est' `d_ste' `d_dof'
	putexcel I`row1' = (r(eststar))
	putexcel I`row2' = `d_ste', nformat("(0.000)")
	
	*Scaled difference
	local m_diff = `m_f' - `m_m'
	local scd_est = `d_est' / `m_diff'
	local scd_ste = `d_ste' / `m_diff'
		
	getstars `scd_est' `scd_ste' `d_dof'
	putexcel J`row1' = (r(eststar))
	putexcel J`row2' = `scd_ste', nformat("(0.000)")

	
	
	local row1 = `row1' + 2
	local row2 = `row2' + 2
	
	}
	